import 'package:core_package/ui/widget/my_asset_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_unionad/core/configuration.dart';
import 'package:flutter_app_unionad/model/share_pic_model.dart';
import 'package:flutter_app_unionad/request/facility_request.dart';
import 'package:flutter_app_unionad/ui/my_facility/widget/recharge_finish_ad_widget.dart';
import 'package:flutter_app_unionad/ui/my_facility/widget/select_pay_type_widget.dart';
import 'package:sharesdk_plugin/sharesdk_defines.dart';
import 'package:sharesdk_plugin/sharesdk_defines.dart';
import 'package:sharesdk_plugin/sharesdk_interface.dart';
import 'package:sharesdk_plugin/sharesdk_plugin.dart';
import 'package:core_package/core_package.dart';

class ShareBottomWidget extends StatelessWidget {
  final Function()? shareFinish;

  SharePicModel? item;

  ShareBottomWidget({
    Key? key,
    this.shareFinish,
    this.item,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return buildBottomWidget(context);
  }

  Widget buildBottomWidget(BuildContext context) {
    return Container(
      width: 355.px,
      height: 57.px,
      child: Stack(
        children: [
          Positioned.fill(
            child: MyAssetImage(
              "icon_bg_4",
              fit: BoxFit.fill,
            ),
          ),
          Positioned(
            left: 0,
            top: 0,
            bottom: 0,
            width: 75.px,
            child: MyAssetImage(
              "icon_bg_4_left",
              fit: BoxFit.fill,
            ),
          ),
          Positioned(
            left: 0,
            top: 0,
            bottom: 0,
            width: 75.px,
            child: Container(
              alignment: Alignment.center,
              child: Text(
                "分享\n有礼",
                style: TextStyle(
                  color: Colors.white,
                  fontWeight: MyFontWeight.bold,
                  fontSize: MyFont.font14,
                ),
              ),
            ),
          ),
          Positioned(
            left: 80.px,
            top: 0,
            bottom: 0,
            child: Container(
              alignment: Alignment.center,
              child: Text(
                "分享到朋友圈，\n既得20，000金币",
                style: TextStyle(
                  color: Colors.white,
                  fontWeight: MyFontWeight.regular,
                  fontSize: MyFont.font12,
                ),
              ),
            ),
          ),
          Positioned(
            right: 20.px,
            top: 13.5.px,
            child: GestureDetector(
              onTap: () {
                shareOnTap(context);
              },
              child: Container(
                width: 84.px,
                height: 30.px,
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage(MyAssetsImages.setAssetsImagesPath("icon_bg_5")),
                    fit: BoxFit.fill,
                  ),
                ),
                alignment: Alignment.center,
                child: Text(
                  "去分享",
                  style: TextStyle(
                    color: Colors.white,
                    fontWeight: MyFontWeight.bold,
                    fontSize: MyFont.font12,
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  void shareOnTap(BuildContext context) {
    // return;
    ShowBottomAlertDialog.showBottomDialog(
      context,
      builder: (ctx) {
        return SelectPayTypeWidget(
          title: '选择分享方式',
          icons: [/*'wx_1',*/ 'wechat_moments'],
          weChatPayOnTop: () {
            //
            share(false);
          },
          alipayPayOnTop: () {
            //
            share(false);
          },
        );
      },
      height: 168.px + SizeFill.statusHeight!,
    );
  }

  void share(bool isSession) {
    this.shareFinish?.call();
    SSDKMap ssdkMap = SSDKMap()
      ..setGeneral(
          //title	标题（String）
          item!.title!,
          // text	文本（String）

          '',
          //images	图片数组ios使用（dynamic）
          [MyAssetsImages.setAssetsImagesPath('icon_logo_1.png')],
          //imageUrlAndroid	url图片地址（String）
          "",
          "",
//          "${imageUrl}",
          //url	url地址（String）
          "${Configuration.h5Share}${FacilityRequest.encodeBase64(UserCacheUil.getString(Configuration.mobile) ?? '')}",
          //右侧图片地址
          MyAssetsImages.setAssetsImagesPath('icon_logo_1.png'),
          //musicUrlAndroid	音乐url地址（String）
          "",
          //videoUrlAndroid	视频url地址（String）
          "",
          //filePath	文件地址（String）
          "",
          //分享类型
          SSDKContentTypes.webpage);
    // ShowToastWidget.showToast(msg: '开始分享');
    try {
      SharesdkPlugin.share(isSession ? ShareSDKPlatforms.wechatSession : ShareSDKPlatforms.wechatTimeline, ssdkMap,
          (state, map1, map2, err) {
        // ShowToastWidget.showToast(msg: '${err.code} ---${err.userInfo}');
        //
        if (state == SSDKResponseState.Success) {}
      });
    } catch (e) {
      ShowToastWidget.showToast(msg: '$e');
    }
  }
}
